﻿using Microsoft.AspNetCore.Mvc;
using System.ComponentModel.DataAnnotations;

namespace BindTryParseMVC.Controllers
{
    public class TestModelValidateController : Controller
    {
        public IActionResult Index()
        {
            return View();
        }


        [AcceptVerbs("GET","POST")]
        public IActionResult VerifyPhone([RegularExpression(@"^\d{3}-\d{3}-\d{4}")] string phone)
        {
            if (!ModelState.IsValid)
            {
                return Json($"Phone {phone} has an invalid format. Format:###-###-####");
            }
            return Json(true);
        }

        

    }

    
}
